import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/index'

Vue.use(Router)

const router = new Router({
    routes: [{
            path: '/',
            name: 'Index',
            component: () =>
                import ('../views/index/Index'),
            meta: {
                activeNav: {
                    title: 'HOME',
                    bottomNavIsShow: true,
                    isBack: false
                },
                deepth: 1,
                keepAlive: true
            }
        },
        {
            path: '/Menu',
            name: 'Menu',
            component: () =>
                import ('../views/menu/Menu'),
            meta: {
                activeNav: {
                    title: 'MENU',
                    bottomNavIsShow: true,
                    isBack: false
                },
                deepth: 1,
                keepAlive: true
            }
        },
        {
            path: '/mine',
            name: 'Mine',
            component: () =>
                import ('../views/mine/mine'),
            meta: {
                activeNav: {
                    title: 'COLLECTION',
                    bottomNavIsShow: true,
                    isBack: false
                },
                deepth: 1,
                keepAlive: true
            }
        },
        {
            path: '/innerpage',
            name: 'innerPage',
            component: () =>
                import ('../views/innerPage/innerPage'),
            meta: {
                activeNav: {
                    title: 'ARTICLE',
                    bottomNavIsShow: true,
                    isBack: false
                },
                deepth: 2,
                keepAlive: true
            }
        },
        {
            path: '/article',
            name: 'Article',
            component: () =>
                import ('../views/innerPage/article'),
            meta: {
                activeNav: {
                    title: 'ARTICLE',
                    bottomNavIsShow: true,
                    isBack: true
                },
                deepth: 3,
                keepAlive: false
            }
        }
    ]
})

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};

router.beforeEach(({ meta }, from, next) => {
    store.commit('SET_BOTTOM_NAV_SHOW', meta.activeNav.bottomNavIsShow)
    store.commit('SET_ACTIVE_NAV_TITLE', meta.activeNav.title)
    next()
})

export default router
